#include "stdafx.h"

#include "GlobalFunctions.h"


BOOL IsNumber(char * str, int & number)
{
    if(str==NULL || *str=='\0') return FALSE;
    char *endptr;

    if(*str=='0')
    {
        ++str;
        if(*str=='x') 
        {
            ++str;
            number = strtol(str,&endptr,16);
        }
        else number = strtol(str,&endptr,8);
    }
    else number = strtol(str,&endptr,10);
    if(*endptr!='\0') return FALSE;
    return TRUE;
}


void ShowErrorMessage(const char *str)
{
    MessageBox(NULL,str,"8085 Instruction Set Simulator",MB_OK|MB_ICONEXCLAMATION);
}


HINSTANCE GotoURL(LPCTSTR url, int showcmd)
{
    return ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd);
}


// formate the error message obtained from GetLastError
CString GetWindowsErrorMessage( )
{
	char buf[1024];

	::FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, &buf, GetLastError( ), 0, buf, sizeof( buf )- 1, 0 );

	return CString( buf );
}